package com.wowudi.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wowudi.dto.ListDto;
import com.wowudi.entity.TreatResult;
import com.wowudi.service.DepartmentClassService;
import com.wowudi.service.PatientsService;
import com.wowudi.service.TreatResultService;
import com.wowudi.util.MsgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("api/pati/treat")
public class TreatController {

    @Autowired
    private TreatResultService treatResultService;
    @Autowired
    private DepartmentClassService departmentClassService;
    @Autowired
    private PatientsService patientsService;
    @RequestMapping("findTreat")
    public Page<TreatResult> findTreat(Integer pageym ,Integer pagesize,String cardid,String patiname) {
        Page<TreatResult> page = new Page<TreatResult>(pageym,pagesize);
        this.treatResultService.getAllBynameandid(page,cardid,patiname);
        return page;
    }
    //删除
    @RequestMapping("delTreat")
    public MsgUtil delTreat(Integer id) {
        TreatResult treatResult=this.treatResultService.getById(id);
        treatResult.setTrIsdel(1);
        boolean bool=this.treatResultService.updateById(treatResult);
        if (bool){
            return new MsgUtil(true,"删除成功",null);
        }else {
            return new MsgUtil(false, "删除失败", null);
        }
    }
    //显示修改ui
    @RequestMapping("upTreatui")
    public TreatResult upTreatui(Integer id) {
        TreatResult treatResult=this.treatResultService.getById(id);
        return  treatResult;
    }
    @RequestMapping("getListDto")
    public ListDto getListDto() {
        ListDto listDto=new ListDto(null,null,this.departmentClassService.list(),this.patientsService.list(),null);
        return listDto;
    }
    //添加
    @RequestMapping("addTreat")
    public MsgUtil addPati(@RequestBody TreatResult treatResult) {
        treatResult.setTrCreateTime(new Date());
        treatResult.setTrIsdel(0);
        boolean bool=this.treatResultService.save(treatResult);
        if (bool){
            return new MsgUtil(true,"添加成功",null);
        }else {
            return new MsgUtil(false,"添加失败",null);
        }
    }
    //修改
    @RequestMapping("upTreat")
    public MsgUtil upPati(@RequestBody TreatResult treatResult) {
        boolean bool=this.treatResultService.updateById(treatResult);
        if (bool){
            return new MsgUtil(true,"修改成功",null);
        }else {
            return new MsgUtil(false, "修改失败", null);
        }
    }
}
